package com.example.votemanage.controller;

import cn.hutool.core.util.StrUtil;
import com.example.votemanage.config.AuthAccess;
import com.example.votemanage.entity.AuctionUser;
import com.example.votemanage.exception.ServiceException;
import com.example.votemanage.mapper.AuctionUserMapper;
import com.example.votemanage.service.AuctionUserService;
import com.example.votemanage.service.Impl.AuctionUserServiceImpl;
import io.micrometer.common.util.StringUtils;
import lombok.SneakyThrows;
import com.example.votemanage.config.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.swing.*;

@RestController
public class AuctionUserController {
    @Autowired
    AuctionUserServiceImpl auctionUserService;
    @SneakyThrows
    @PostMapping("/login")
    public Result login(@RequestBody AuctionUser user){
        if(StrUtil.isBlank(user.getUserName()) || StrUtil.isBlank(user.getUserPassword())){
            System.out.println("user = " + user);
            return Result.error("数据输入不合法");
        }
        user=auctionUserService.login(user);
        return Result.success(user);
    }
    @SneakyThrows
    @PostMapping("/register")
    public Result register(@RequestBody AuctionUser auctionUser){
        System.out.println("bookemanage = " + auctionUser);
        boolean saveResult = auctionUserService.save(auctionUser);
        if (!saveResult) {
            System.out.println("saveResult = " + false);
            return Result.error("注册失败");
        } else {
            return Result.success(auctionUser);
        }
    }
//    @RequestMapping("/items")
//    public List<AuctionItem> getItems(
//            @RequestParam(required = false) String name,
//            @RequestParam(required = false) String description,
//            @RequestParam(required = false) String startTime,
//            @RequestParam(required = false) String endTime,
//            @RequestParam(required = false) Double startPrice) {
//        QueryWrapper<AuctionItem> queryWrapper = new QueryWrapper<>();
//        if (name != null && !name.isEmpty()) {
//            queryWrapper.like("name", name);
//        }
//        if (description != null && !description.isEmpty()) {
//            queryWrapper.like("description", description);
//        }
//        if (startTime != null && !startTime.isEmpty()) {
//            queryWrapper.ge("start_time", startTime);
//        }
//        if (endTime != null && !endTime.isEmpty()) {
//            queryWrapper.le("end_time", endTime);
//        }
//        if (startPrice != null) {
//            queryWrapper.ge("start_price", startPrice);
//        }
//
//        return auctionItemService.list(queryWrapper);
//    }
}
